<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: UserActivity.php 425 2011-01-05 10:30:30Z steen.rabol $
 *
 */

Prado::using('Application.Common.Data.PortalUserActivityRecord');
Prado::using('Application.Common.Data.PortalUserRecord');

class UserActivity extends PortalAdminPage
{

	public function getDataRows($offset, $rows)
	{
		return PortalUserActivityRecord::finder()->findAll("limit $offset,$rows");
	}

	public function onLoad($param)
	{
		parent::onLoad($param);

		if(!$this->IsPostBack)
		{
			$this->rpUserActivity->VirtualItemCount	= $this->RowCount;
			$this->rpUserActivity->DataSource		= $this->getDataRows(0,$this->rpUserActivity->PageSize);
			$this->rpUserActivity->dataBind();
		}
	}

	protected function getRowCount()
    {
        return $this->DataAccess->createCommand("select count(id) from tbluseractivity")->queryScalar();
    }

	public function pageChanged($sender,$param)
    {
        // change the current page index to the new one
        $this->rpUserActivity->CurrentPageIndex=$param->NewPageIndex;
        $offset=$param->NewPageIndex*$this->rpUserActivity->PageSize;
        $this->rpUserActivity->DataSource=$this->getDataRows($offset,$this->rpUserActivity->PageSize);
        $this->rpUserActivity->dataBind();
    }

	public function GetCssStyle($item)
	{
		switch($item->priority)
		{
			case 0:	return 'background-color:#FFFF80';break;
			case 1:	return 'background-color:#80FF80';break;
			case 2:	return 'background-color:#FF8080';break;
		}
	}

	public function ClearActivity($s,$p)
	{
		$this->DataAccess->createCommand("delete from tbluseractivity")->execute();
		$this->gotoPage('Admin.UserActivity');
	}
}
?>